import Http from '@/lib/axios'

const iSpacePreUrl = '/viewcc'


export default class Profile extends Http  {
  // 获取企业画像评估结果
  getEnterpriseProfileResult(path: string) {
    return this.get(`${iSpacePreUrl}/site/buildings`, { path } )
  }

  // 获取企业画像评估规则
  async getEnterpriseProfileRule(path: string) {
    const res = await this.post(`${iSpacePreUrl}/get`, { key: path })
    return JSON.parse((res.value || '[]'))
    // return []
  }

  // 保存企业画像评估规则
  async saveEnterpriseProfileRule(path: string, data) {
    return await this.post(`${iSpacePreUrl}/set`, { key: path, value: JSON.stringify(data) })
    // return 
  }

  // 获取企业画像评估内容
  async getEnterpriseProfileContent(path: string) {
    const res = await this.post(`${iSpacePreUrl}/get`, { key: path })
    let list = JSON.parse((res.value || '[]'))
    if(list.length === 0) {
      list = [
          {id: 1, name: '员工违规行为', proportion: '18', type: 1, list: []},
          {id: 2, name: '车辆违规', proportion: '5', type: 1, list: []},
          {id: 3, name: '消防演练结果', proportion: '22', type: 2, list: []},
          {id: 4, name: '消防培训得分', proportion: '10', type: 2, list: []},
      ]
      await this.saveEnterpriseProfileContent('/enterprise/profile/content', list)
    }
    return list
  }

  // 保存企业画像评估内容
  async saveEnterpriseProfileContent(path: string, data) {
    return await this.post(`${iSpacePreUrl}/set`, { key: path, value: JSON.stringify(data) })
  }

  // 获取企业画像等级
  async getEnterpriseProfileLevel(path: string) {
    const res = await this.post(`${iSpacePreUrl}/get`, { key: path })
    return JSON.parse((res.value || '[]')) 
  }
  // 保存企业画像等级
  async saveEnterpriseProfileLevel(path: string, data: any) {
    return await this.post(`${iSpacePreUrl}/set`, { key: path, value: JSON.stringify(data) })
  }
}
